import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';


export const deleteMenuBindPermPolicy = (params) => {
  let url = '/system-service/authorize/deleteMenuBindPermPolicy'
  return defHttp.delete({url: url, params});
}

export const listSubjectPermission = (params) => {
  let url = '/system-service/authorize/listSubjectPermission'
  return defHttp.get({url: url, params});
}

export const assignPermPolicyToRole = (params) => {
  let url = '/system-service/authorize/assignPermPolicyToRole'
  return defHttp.post({url: url, params});
}

export const assignPermPolicyToOauthClient = (params) => {
  let url = '/system-service/authorize/assignPermPolicyToOauthClient'
  return defHttp.post({url: url, params});
}

export const assignPermPolicyToUser = (params) => {
  let url = '/system-service/authorize/assignPermPolicyToUser'
  return defHttp.post({url: url, params});
}


export const listMenuResourceByUrl = (params) => {
  return defHttp.get({url: '/system-service/resource/listMenuResourceByUrl', params });
}


export const getPermissionApply = (params) => {
  return defHttp.get({url: '/system-service/permissionApply/get', params});
}

export const pagePermissionApply = (params) => {
  return defHttp.get({url: '/system-service/permissionApply/page', params});
}

export const saveOrupdatePermissionApply = (params, isUpdate) => {
  let url = '/system-service/permissionApply/' + (isUpdate ? 'update' : 'save');
  return defHttp.post({url: url, params});
}

/**
 * 保存权限申请
 */
export const savePermissionApply = (params) => {
  return defHttp.post({url: '/system-service/permissionApply/saveApply', params});
}

/**
 * 撤销权限申请
 */
export const undoPermissionApply = (params, handleSuccess) => {
  return defHttp.post({url: '/system-service/permissionApply/undo', data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 保存权限审批
 */
export const savePermissionApproval = (params) => {
  return defHttp.post({url: '/system-service/permissionApply/approval', data: params}, {joinParamsToUrl: true});
}

export const deletePermissionApply = (params, handleSuccess) => {
  return defHttp.delete({url: '/system-service/permissionApply/delete', data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const batchdeletePermissionApply = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({
        url: '/system-service/permissionApply/batchDelete', data: params
     }, { joinParamsToUrl: true }).then(() => {
        handleSuccess(); 
     });
    }
  });
}


export const getPermissionPolicy = (params) => {
  return defHttp.get({url: '/system-service/permissionPolicy/get', params});
}

export const pagePermissionPolicy = (params) => {
  return defHttp.get({url: '/system-service/permissionPolicy/page', params});
}

export const saveOrUpdatePermissionPolicy = (params, isUpdate) => {
  let url = '/system-service/permissionPolicy/' + (isUpdate ? 'update' : 'save');
  return defHttp.post({url: url, params});
}

export const deletePermissionPolicy = (params, handleSuccess) => {
  return defHttp.delete({url: '/system-service/permissionPolicy/delete', data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const batchDeletePermissionPolicy = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({
        url: '/system-service/permissionPolicy/batchDelete', data: params
     }, { joinParamsToUrl: true }).then(() => {
        handleSuccess(); 
     });
    }
  });
}
